package logic.abilities;

import logic.characters.Player;

/**
 * @author Unai
 * 
 */
public class DoubleJump extends Ability{
	public boolean firstJump;
	public boolean secondJump;
	
	/**
	 * @param player
	 */
	public DoubleJump(Player player) {
		super(player);
		cost = 3;
		pasive = true;
	}

	/* (non-Javadoc)
	 * @see logic.abilities.Ability#effect()
	 * Permite saltar una vez en el aire
	 */
	@Override
	public void effect() {
		if (!secondJump && player.movementAllowed) {
			if ((firstJump && player.stamina >= cost) || !firstJump) {
				if (firstJump && player.stamina >= cost) {
					player.stamina -= cost;
				}
				player.velY = -250 * player.jump;
				player.falling = true;
				player.jumping = true;
				player.onPlatform = false;
				player.jump = player.originalJump;
				player.speed = player.originalSpeed;
				if (player.lookingRight) {
					player.updateIcon("resources" + player.getClass().getSimpleName() + "/JR.gif");
				} else {
					player.updateIcon("resources" + player.getClass().getSimpleName() + "/JL.gif");
				}
				if (firstJump) {
					secondJump = true;
				}
				firstJump = true;
			}
		}


	}

	/* (non-Javadoc)
	 * @see logic.abilities.Ability#modifyAttributes()
	 * Activa el flag para ejecutar el doble salto en ves del normal
	 */
	@Override
	public void modifyAttributes() {
		player.doubleJump = true;
		
	}

	/* (non-Javadoc)
	 * @see logic.abilities.Ability#updateFlags()
	 * Actaliza flags para evaluar si es posible saltar 
	 */
	@Override
	public void updateFlags() {
		if (player.onPlatform) {
			firstJump = false;
			secondJump = false;
		} else {
			firstJump = true;
		}
		
	}

}
